// part1:C10:ex10.20.cpp
// count_if, total length of words.
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include "make_plural.h"
using namespace std;

inline void outpu_words(vector<string>& words) {
  for (auto iter = words.begin(); iter != words.end(); iter++) {
    cout << *iter << " "; 
  }
  cout << endl;
}

void biggies(vector<string>& words,
             vector<string>::size_type sz) {
  outpu_words(word);

  auto bc = count_if(words.begin(), words.end(),
                     [sz](const string &s) {
                       return s.size() >= sz;
                     });
  cout << bc << " " << make_plural(bc, "word", "s")
       << " of length " << sz << " or longer" << endl;
}

int main(int argc, char *argv[]) {
  ifstream in(argv[]);
  if (!in) {
    cout << "failed open input file!" << endl;
    exit(1);
  }

  vector<string> words;
  string word;
  while (in >> word) {
    words.push_back(word); 
  }
  biggies(words, 6);

  return 0;
}
